<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript" src="<%=ApplicationPath%>/video/ckplayer/ckplayer/ckplayer.js"></script>
<style>
.tableDiv{
	width:710px;
	height: 610px;
	text-align: center;
}
.imageDiv{
	width:350px;
	height:210px;
	text-align: center;
}
img{
	max-width: 350px;
	max-height: 210px;
}
</style>
<script>
	$(document).ready(function () {

		try {
			//根据返回数据的条数创建
			var num = parseInt("${num}",10);
			// console.log("num="+num);
			var objImgs= new Array();
			var objVideos = new Array();
			if (num > 0) {
				//动态创建表格
				for (var i = 0; i < num; i++) {
					//获取数据，只需要视频和图片数据
					var ojbTemp = getObject(i);
					if(ojbTemp.fileType=="0"){
						objImgs.push(ojbTemp);
					}
					if(ojbTemp.fileType == "2"){
						objVideos.push(ojbTemp);
					}
				}
				var cout = objImgs.length + objVideos.length;
				//创建区域
				createDiv(cout);
				//插入视频
				for(var k=0 ; k<objVideos.length ; k++){
					addVideo(k,objVideos[k]);
				}
				//插入图片
				for(var i=0 ; i<objImgs.length ; i++){
					addImage(i+objVideos.length,objImgs[i]);
				}

			}
		} catch (error) {
			console.log(error);
		}

		//添加按钮
		// addBtn();

	});

//添加一行数据
function addtr(index){
	//var downloadPath = "<%=ApplicationPath%>/adasAlarm/download.action?adasAttachmentId="+ resourceId;
	var strTr = "<tr><td><span>附件类型</span></td>";//行头
	strTr +=getAttInfo(index);
	//strTr +="<td colspan=2 align='center'><a href=\"javascript:window.open('" + downloadPath+ "');\">下载</a></td>";//添加附件下载列
	strTr +="</tr>";//行尾
	$("#aaiTbody").append(strTr);
}

//添加视频到指定区域
function addVideo(index,obj){
	var strTemp = "<%=ApplicationPath%>/adasAttachment/"+getFileDate(obj.updateDate)+"/"+obj.fileName;
	// console.log(strTemp);
	strTemp = "<video src='"+strTemp+"' type='video/mp4'width='350' height='210' controls='controls' autoplay='autoplay'><video>";
	$("#div"+index).append(strTemp);
}

//添加图片到指定区域
function addImage(index,obj){
	var strTemp = "<%=ApplicationPath%>/adasAttachment/"+getFileDate(obj.updateDate)+"/"+obj.fileName;
	// console.log(strTemp);
	strTemp = "<img src='"+strTemp+"'>";
	$("#div"+index).append(strTemp);
}

//创建显示区域
function createDiv(cout){
	var coutTemp = Math.ceil(cout/2);
	if(coutTemp > 0){
		//开始创建
		for(var i=0 ; i< coutTemp ; i++){
			var strTemp = "<tr><td><div id='div"+(i*2)+"' class='imageDiv'></div></td><td><div id='div"+(i*2+1)+"' class='imageDiv'></div></td></tr>";
			$("#aaiTbody").append(strTemp);
		}
	}
}

//根据索引获取列表中的数据
function getObject(index){
	var obj = new Object();
	switch(index){
		case 0:
		obj.fileType = "${list[0].fileType}";
		obj.updateDate = "${list[0].updateDate}";
		obj.fileName = "${list[0].fileName}";
		break;
		case 1:
		obj.fileType = "${list[1].fileType}";
		obj.updateDate = "${list[1].updateDate}";
		obj.fileName = "${list[1].fileName}";
		break;
		case 2:
		obj.fileType = "${list[2].fileType}";
		obj.updateDate = "${list[2].updateDate}";
		obj.fileName = "${list[2].fileName}";
		break;
		case 3:
		obj.fileType = "${list[3].fileType}";
		obj.updateDate = "${list[3].updateDate}";
		obj.fileName = "${list[3].fileName}";
		break;
		case 4:
		obj.fileType = "${list[4].fileType}";
		obj.updateDate = "${list[4].updateDate}";
		obj.fileName = "${list[4].fileName}";
		break;
		case 5:
		obj.fileType = "${list[5].fileType}";
		obj.updateDate = "${list[5].updateDate}";
		obj.fileName = "${list[5].fileName}";
		break;
		case 6:
		obj.fileType = "${list[6].fileType}";
		obj.updateDate = "${list[6].updateDate}";
		obj.fileName = "${list[6].fileName}";
		break;
		case 7:
		obj.fileType = "${list[7].fileType}";
		obj.updateDate = "${list[7].updateDate}";
		obj.fileName = "${list[7].fileName}";
		break;
		case 8:
		obj.fileType = "${list[8].fileType}";
		obj.updateDate = "${list[8].updateDate}";
		obj.fileName = "${list[8].fileName}";
		break;
		case 9:
		obj.fileType = "${list[9].fileType}";
		obj.updateDate = "${list[9].updateDate}";
		obj.fileName = "${list[9].fileName}";
		break;
	}
	return obj;
}

//根据文件路径获取日期目录
function getFileDate(updateDate){
	var arrayTemp = updateDate.split(" ");
	return arrayTemp[0];
}

//获取文件类型
function getfileType(fileType){
	switch(fileType){
		case "0":
		return "图片";
		case "2":
		return "视频";
		case "3":
		return "文字";
		default:
		return "其他";
	}
}

//添加按钮
function addBtn(){

	var strBtn = "<tr><td colspan=6 align='center'><input type='button' onclick='btnClick();'"
					+"value='关闭'></td></tr>";
	$("#aaiTbody").append(strBtn);
}

function btnClick(){
	window.parent.closeCommandWindow();
}
</script>

</head>
<body>
	<div class="tableDiv">
		<table width="100%" class="TableBlock">
			<tbody id="aaiTbody">
				<tr style="text-align:center;">
					<td colspan="6" >
						<span >${message}</span>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</body>

</html>